package cn.jiedanba.cacert.common.ca.crl.domain;

import java.io.Serializable;
import java.security.cert.CRLReason;
import java.util.Date;

import com.alibaba.fastjson.annotation.JSONField;

import cn.jiedanba.cacert.common.util.DateUtil;

public class PkiCRLRevoke implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 证书序列号
	 */
	private String sn;

	/**
	 * 吊销时间
	 */
	@JSONField(format = DateUtil.TO_SECOND)
	private Date revokeDate;

	/**
	 * 吊销理由
	 */
	private String reason;

	public String getSn() {
		return sn;
	}

	public void setSn(String sn) {
		this.sn = sn;
	}

	public Date getRevokeDate() {
		return revokeDate;
	}

	public void setRevokeDate(Date revokeDate) {
		this.revokeDate = revokeDate;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(CRLReason reason) {
		if (CRLReason.UNSPECIFIED.equals(reason)) {
			this.reason = "";
		} else if (CRLReason.KEY_COMPROMISE.equals(reason)) {
			this.reason = "密钥泄漏(1)";
		} else if (CRLReason.CA_COMPROMISE.equals(reason)) {
			this.reason = "CA泄漏(2)";
		} else if (CRLReason.AFFILIATION_CHANGED.equals(reason)) {
			this.reason = "附属关系已更改 (3)";
		} else if (CRLReason.SUPERSEDED.equals(reason)) {
			this.reason = "被取代 (4)";
		} else if (CRLReason.CESSATION_OF_OPERATION.equals(reason)) {
			this.reason = "停止操作 (5)";
		} else if (CRLReason.CERTIFICATE_HOLD.equals(reason)) {
			this.reason = "证书挂起 (6)";
		} else if (CRLReason.REMOVE_FROM_CRL.equals(reason)) {
			this.reason = "从 CRL中删除 (8)";
		} else if (CRLReason.PRIVILEGE_WITHDRAWN.equals(reason)) {
			this.reason = "证书撤销 (9)";
		} else if (CRLReason.AA_COMPROMISE.equals(reason)) {
			this.reason = "疑似私钥泄露(10)";
		} else {
			this.reason = "Unknown CRL reason";
		}
	}

}
